/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RecepcionarDocGUI.java
 *
 * Created on 13/09/2012, 01:37:27 AM
 */
package Gui;

import ClassControl.CtrRecepcion;
import ClassEntidad.DocExterno;
import ClassEntidad.Funcionario;
import ClassEntidad.PerExterna;
import ClassEntidad.Persona;
import ClassEntidad.Sistema;
import ClassEntidad.TRD;
import Servicios.DocExternoJpaController;
import java.util.Date;
import javax.swing.JOptionPane;
import util.CparaCombo;

/**
 *
 * @author borisgr04
 */
public class RecepcionarDocGUI extends javax.swing.JFrame implements IRecibir {

    DocExternoJpaController docExt = new DocExternoJpaController(Sistema.instancia.getEmf());
    private BuscarPerExtGUI guiPerExt;
    private PerExterna PerExt = new PerExterna();
    PerExterna pe;
    private int serieTRD;
    CtrRecepcion cd = new CtrRecepcion(Sistema.instancia().getEmf());

    /**
     * Creates new form RecepcionarDocGUI
     */
    public RecepcionarDocGUI() {
        initComponents();
        inicializar();
        this.setResizable(false);
        this.setLocationRelativeTo(null);

    }

    void inicializar() {
        //Llena Comobo Box Dependencia
        Funcionario fun = new Funcionario();
        for (Persona f : Sistema.instancia.getFuncionarios()) {
            this.depDestinoC.addItem(new CparaCombo(f.getNroIde(), f.getNombres()));
        }
        iniFormularios.mostrarUsuarioActual(usuarioLabel);
        Habilitar(false);

        TRD trd = new TRD();
        int i = 0;
        for (TRD serie : Sistema.instancia.getTRD()) {
            if (i == 0) {
                this.serieC.addItem(new CparaCombo(serie.getId_Serie(), serie.getSerie().toUpperCase()));
            }
            i++;
            //System.out.print(serie.getSerie());
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        nuevoB = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        DistribuirB = new javax.swing.JButton();
        cancelB = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        cerrarB = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        fechaT = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        nRadicadoB = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        docRelacionadoT = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        asuntoT = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        resumenT = new javax.swing.JTextArea();
        jLabel10 = new javax.swing.JLabel();
        tVencimintoSp = new javax.swing.JSpinner();
        jLabel6 = new javax.swing.JLabel();
        FoliosSp = new javax.swing.JSpinner();
        jPanel3 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        identPerRemB = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        nombresPEB = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        dirPEB = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        correoPEB = new javax.swing.JTextField();
        buscarPerExtB = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        depDestinoC = new javax.swing.JComboBox();
        UsuarioL = new javax.swing.JLabel();
        usuarioLabel = new javax.swing.JLabel();
        autorT = new javax.swing.JLabel();
        serieC = new javax.swing.JComboBox();

        setTitle("VENTANILLA UNICA - RECEPCION DE DOCUMENTOS");

        jToolBar1.setRollover(true);

        nuevoB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/New.png"))); // NOI18N
        nuevoB.setText("Nuevo");
        nuevoB.setFocusable(false);
        nuevoB.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        nuevoB.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        nuevoB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nuevoBActionPerformed(evt);
            }
        });
        jToolBar1.add(nuevoB);
        jToolBar1.add(jSeparator3);

        DistribuirB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/save.png"))); // NOI18N
        DistribuirB.setText("Guardar");
        DistribuirB.setFocusable(false);
        DistribuirB.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        DistribuirB.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        DistribuirB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DistribuirBActionPerformed(evt);
            }
        });
        jToolBar1.add(DistribuirB);

        cancelB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/undo.png"))); // NOI18N
        cancelB.setText("Cancelar");
        cancelB.setFocusable(false);
        cancelB.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cancelB.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        cancelB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelBActionPerformed(evt);
            }
        });
        jToolBar1.add(cancelB);
        jToolBar1.add(jSeparator1);

        cerrarB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Log Out_32x32.png"))); // NOI18N
        cerrarB.setText("Cerrar");
        cerrarB.setFocusable(false);
        cerrarB.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cerrarB.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        cerrarB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cerrarBActionPerformed(evt);
            }
        });
        jToolBar1.add(cerrarB);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Recepción de Documentos"));

        jLabel1.setText("Fecha y Hora");

        fechaT.setEnabled(false);

        jLabel2.setText("N° Radicado");

        nRadicadoB.setEnabled(false);

        jLabel3.setText("Documento Relacionado");

        jLabel4.setText("Asunto");

        jLabel5.setText("Resumen");

        resumenT.setColumns(20);
        resumenT.setRows(5);
        jScrollPane1.setViewportView(resumenT);

        jLabel10.setText("N° Folio");

        tVencimintoSp.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));

        jLabel6.setText("Tiempo de Rpta (Dias)");

        FoliosSp.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(fechaT, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(nRadicadoB, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 411, Short.MAX_VALUE)
                            .addComponent(docRelacionadoT, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(asuntoT, javax.swing.GroupLayout.DEFAULT_SIZE, 411, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel10)
                        .addGap(18, 18, 18)
                        .addComponent(FoliosSp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(17, 17, 17)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(tVencimintoSp, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(75, 75, 75))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(fechaT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(nRadicadoB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(docRelacionadoT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(asuntoT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(tVencimintoSp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(FoliosSp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Remitente"));

        jLabel12.setText("Documento");

        identPerRemB.setEnabled(false);

        jLabel13.setText("Nombres");

        nombresPEB.setEnabled(false);

        jLabel14.setText("Dirección");

        dirPEB.setEnabled(false);

        jLabel15.setText("Correo");

        correoPEB.setEnabled(false);

        buscarPerExtB.setText("...");
        buscarPerExtB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarPerExtBActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13)
                    .addComponent(jLabel14)
                    .addComponent(jLabel15))
                .addGap(30, 30, 30)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(correoPEB)
                    .addComponent(dirPEB, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(nombresPEB, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(identPerRemB, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buscarPerExtB)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(identPerRemB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buscarPerExtB))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(nombresPEB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(dirPEB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(correoPEB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15)))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Destino"));

        jLabel7.setText("Funcionario");

        UsuarioL.setText("Usuario Actual:");

        usuarioLabel.setText("....");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addGap(18, 18, 18)
                .addComponent(depDestinoC, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(UsuarioL)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(usuarioLabel)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(depDestinoC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(UsuarioL)
                    .addComponent(usuarioLabel))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        serieC.setEnabled(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(96, 96, 96)
                        .addComponent(autorT))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(serieC, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(serieC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(autorT))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void DistribuirBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DistribuirBActionPerformed
        // TODO add your handling code here:

        try {
            CparaCombo depDes = (CparaCombo) depDestinoC.getSelectedItem();
            if (depDes == null) {
                JOptionPane.showMessageDialog(this, "Seleccione Destinatario", Sistema.instancia().getNomApp(), JOptionPane.WARNING_MESSAGE);
                return;
            }
            CparaCombo serie = (CparaCombo) serieC.getSelectedItem();
            if (serie == null) {
                JOptionPane.showMessageDialog(this, "Seleccione Serie", Sistema.instancia().getNomApp(), JOptionPane.WARNING_MESSAGE);
                return;
            }
            if(identPerRemB.getText().isEmpty()){
                    JOptionPane.showMessageDialog(this, "Seleccione Originador del Docuemnto", Sistema.instancia().getNomApp(), JOptionPane.WARNING_MESSAGE);
                    return;
            }


            DocExterno d = new DocExterno();
            d.setAsunto(asuntoT.getText());
            d.setResumen(resumenT.getText());
            d.setPlazoVec(Integer.parseInt(this.tVencimintoSp.getValue().toString()));
            d.setFolios(Integer.parseInt(this.FoliosSp.getValue().toString()));
            if (!docRelacionadoT.getText().isEmpty()) {
                cd.setIdDocRel(Integer.valueOf(docRelacionadoT.getText()));
            }
            cd.setIdeOrigen(identPerRemB.getText());
            cd.setIdeDestino(depDes.getCodigo());
            cd.setIdSerie(Long.valueOf(serie.getCodigo()));
            cd.setDoc(d);
            cd.Guardar();
            if (cd.isValido()) {
                this.nRadicadoB.setText(String.valueOf(cd.getDoc().getNoDocumento()));
                JOptionPane.showMessageDialog(this, cd.getMensaje(), Sistema.instancia().getNomApp(), JOptionPane.INFORMATION_MESSAGE);
                this.Habilitar(false);        // TODO add your handling code here:
                this.limipiar();
            } else {
                JOptionPane.showMessageDialog(this, cd.getMensaje(), Sistema.instancia().getNomApp(), JOptionPane.WARNING_MESSAGE);
            }

        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage(), Sistema.instancia().getNomApp(), JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_DistribuirBActionPerformed

    private void buscarPerExtBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarPerExtBActionPerformed
        // TODO add your handling code here:
        guiPerExt = new BuscarPerExtGUI(this);
        this.guiPerExt.setVisible(true);

    }//GEN-LAST:event_buscarPerExtBActionPerformed

    private void nuevoBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nuevoBActionPerformed
        this.Habilitar(true);        // TODO add your handling code here:
        this.limipiar();

    }//GEN-LAST:event_nuevoBActionPerformed

    private void cerrarBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cerrarBActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_cerrarBActionPerformed

    private void cancelBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBActionPerformed
        // TODO add your handling code here:
        this.limipiar();
        this.Habilitar(false);
    }//GEN-LAST:event_cancelBActionPerformed
    private void Habilitar(boolean var) {
        this.cancelB.setEnabled(var);
        this.DistribuirB.setEnabled(var);
//        this.relDocB.setEnabled(var);
        this.buscarPerExtB.setEnabled(var);
        this.fechaT.setEnabled(var);
        this.asuntoT.setEnabled(var);
        this.resumenT.setEnabled(var);
        this.docRelacionadoT.setEnabled(var);
        this.FoliosSp.setEnabled(var);
        this.tVencimintoSp.setEnabled(var);
        this.depDestinoC.setEnabled(true);
        
    }

    private void limipiar() {
        this.fechaT.setText("");
        this.fechaT.setEnabled(false);
        this.asuntoT.setText("");
        this.resumenT.setText("");
        this.docRelacionadoT.setText("");
        this.nRadicadoB.setText("");
        this.identPerRemB.setText("");
        this.nombresPEB.setText("");
        this.dirPEB.setText("");
        this.tVencimintoSp.setValue(-1);
        this.tVencimintoSp.setValue(0);
        this.depDestinoC.setSelectedIndex(-1);
        this.correoPEB.setText("");
        this.FoliosSp.setValue(0);
        Date f = new Date();
        this.fechaT.setText(f.toString());

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new RecepcionarDocGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton DistribuirB;
    private javax.swing.JSpinner FoliosSp;
    private javax.swing.JLabel UsuarioL;
    private javax.swing.JTextField asuntoT;
    private javax.swing.JLabel autorT;
    private javax.swing.JButton buscarPerExtB;
    private javax.swing.JButton cancelB;
    private javax.swing.JButton cerrarB;
    private javax.swing.JTextField correoPEB;
    private javax.swing.JComboBox depDestinoC;
    private javax.swing.JTextField dirPEB;
    private javax.swing.JTextField docRelacionadoT;
    private javax.swing.JTextField fechaT;
    private javax.swing.JTextField identPerRemB;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTextField nRadicadoB;
    private javax.swing.JTextField nombresPEB;
    private javax.swing.JButton nuevoB;
    private javax.swing.JTextArea resumenT;
    private javax.swing.JComboBox serieC;
    private javax.swing.JSpinner tVencimintoSp;
    private javax.swing.JLabel usuarioLabel;
    // End of variables declaration//GEN-END:variables

    public void Recibir(Persona o) {
        pe = (PerExterna) o;
        this.dirPEB.setText(pe.getDireccion());
        this.identPerRemB.setText(pe.getNroIde());
        this.nombresPEB.setText(pe.getNombres());
        this.correoPEB.setText(pe.getEmail());


    }
}
